package com.fanrui.code.chess.mahjong.round;

import com.fanrui.code.chess.mahjong.AbstractMahjongTable;

public class RoundUtil {
	// singleton
	private RoundUtil() {
	}

	private static class RoundUtilSingleton {
		private static RoundUtil instance = new RoundUtil();
	}

	public static RoundUtil getInstance() {
		return RoundUtilSingleton.instance;
	}

	public MahjongRound createRound(MahjongRound round, MahjongOperationResponse response, AbstractMahjongTable<?> table) {
		switch (response.getType()) {
		case SEND:
			return new MahjongSendRound(response.getOperationId(), table, response);
		case PENG:
			return new MahjongPengRound(response.getOperationId(), table, response);
		case CHI:
			return new MahjongChiRound(response.getOperationId(), table, response);
		case GANG_A:
			return new MahjongGangRound(round.getScoreResponse(), response.getOperationId(), table, response, 4);
		case GANG_M:
			return new MahjongGangRound(round.getScoreResponse(), response.getOperationId(), table, response, 3);
		case GANG_B:
			return new MahjongGangRound(round.getScoreResponse(), response.getOperationId(), table, response, 1);
		case ZIMO:
		case BOOM:
			return new MahjongHuRound(round.getScoreResponse(), table, response, round.isAoutoNext(), false);
		default:
			break;
		}
		return null;
	}
	
	public MahjongRound createQiangGangRound(MahjongRound round, MahjongOperationResponse response, AbstractMahjongTable<?> table) {
		return new MahjongHuRound(round.getScoreResponse(), table, response, round.isAoutoNext(), true);
	}
	
}
